package org.zb.shiro.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.zb.shiro.dao.RoleMapper;
import org.zb.shiro.model.Role;

import com.github.pagehelper.PageHelper;

@Service
public class RoleService {
	
	@Autowired
	private RoleMapper roleMapper;
	
    public Role findById(Long id) {
        return roleMapper.selectByPrimaryKey(id);
    }
    
	public List<Role> findByUserId(Long userId) {
		return roleMapper.selectByUserId(userId);
	}
	
	public List<Role> searchAll(Map<String, Object> role) {
		PageHelper.startPage(1, 10);
		return roleMapper.searchAll(role);
	}
    
    public int saveRole(Role role){
    	return roleMapper.insert(role);
    }
    
    public int updateRole(Role role) {
    	return roleMapper.updateByPrimaryKeySelective(role);
    }
    
    public int patchDeleteByIds(Long[] ids){
    	return roleMapper.patchDeleteByIds(ids);
    }
    
    public int deleteRole(Role role) {
    	return roleMapper.deleteByPrimaryKey(role.getId());
    }
}
